import {createApp} from 'vue'
import './css/style.css'
import App from './App.vue'
import router from "./routers/routers.js";
import {checkLogin} from "./utils/utils.js";
import {getStorageString} from "./utils/localStorage.js";

createApp(App).use(router).mount('#app')

router.beforeEach((to, from) => {
    if (getStorageString('panic') && to.path !== '/panic') {
        return {
            path: '/panic', params: {panic: getStorageString('panic')}
        }
    }
    if (to.meta.requireAuth) {
        console.log(to)
        if (!checkLogin()) {
            return {
                path: '/login', query: {target: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
            }
        }
    }
})